package ooday04;

public class Test {
    public static void main(String[] args) {
        /*
        Master master =new Master();
        Dog dog = new Dog("小黑",1,"黑色");
        Chick chick = new Chick("小花",2,"花色");
        Fish fish = new Fish("小红",1,"红色");
        master.feed(dog);
        master.feed(chick);
        master.feed(fish);
         */



       Animal[] animals = new Animal[5];
       animals[0] = new Dog("小黑",1,"黑色");
       animals[1] = new Dog("小白",1,"白色");
       animals[2] = new Chick("坤坤",3,"黑白色");
       animals[3] = new Fish("小金",1,"金色");
       animals[4] = new Fish("小花",1,"花色");
       for (int i = 0;i<animals.length;i++){
           System.out.println(animals[i].name);
           animals[i].eat();
           animals[i].drink();
           //向下造型/强制类型转换，成功的条件只有如下两种：
           //1)引用所指向的对象，就是该类型
           //2)引用所指向的对象，实现了该接口或继承了该类
           //向下造型(强转)：先得有向上造型，Animal animal = new Dog();引用所指对象是Dog
                                      //Dog dog = (Dog)animal1;


           //    对象                类型
           if(animals[i] instanceof Dog){
               Dog dog = (Dog) animals[i];
               dog.guardHome();
               dog.swim();
           }
           if(animals[i] instanceof Fish){
               Fish fish = (Fish) animals[i];
               fish.swim();
           }
           if(animals[i] instanceof Chick){
               Chick chick = (Chick)animals[i];
               chick.layEggs();
               if(animals[i] instanceof Swim){
                   Swim s = (Swim)animals[i];
                   s.swim();
               }
           }















       }
    }
}
